package cn.rukbat.demo3.config;

import cn.rukbat.demo3.interceptor.PasswordlessResourceInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    
    @Autowired
    private PasswordlessResourceInterceptor passwordlessResourceInterceptor;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(passwordlessResourceInterceptor)
                .addPathPatterns("/protected/**");
    }
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 公开静态资源
        registry.addResourceHandler("/public/**")
                .addResourceLocations("classpath:/static/public/");
        
        // 受保护的静态资源
        registry.addResourceHandler("/protected/**")
                .addResourceLocations("classpath:/static/protected/");
    }
}
